﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace storeSMS
{
    public partial class frmlinker : Form
    {
        DataSet ds = new DataSet();
        OleDbDataAdapter command;
        public frmlinker()
        {
            InitializeComponent();
        }

        private void frmlinker_Load(object sender, EventArgs e)
        {
            dgvlinkers.AutoGenerateColumns = false;
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath.ToString() + "\\db\\store.mdb" + ";Persist Security Info=True";
            OleDbConnection connection = new OleDbConnection(connectionString);
            
                ds = new DataSet();
                try
                {
                    connection.Open();
                    command = new OleDbDataAdapter("select ID,uname,uphone,umark from linkers", connection);
                    command.Fill(ds, "ds");
                    dgvlinkers.DataSource = ds.Tables[0];
                }
                catch (System.Data.OleDb.OleDbException ex)
                {
                    MessageBox.Show( ex.Message);
                }                
           
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ds.HasChanges())
            {
                //用SqlCommandBuilder自动为SqlDataAdapter生成Insert、Update、Delete命令
                OleDbCommandBuilder cb = new OleDbCommandBuilder(command);
                command.Update(ds.Tables["ds"]);
                dgvlinkers.Update();
                MessageBox.Show("保存成功！");
            }
        }
    }
}
